<?php
class EvaluateddrugsController extends AppController{
	public function insert($data){
		$this->data['Evaluateddrug']['claimid']=$data[0];
		$this->data['Evaluateddrug']['generic_name']=$data[1];
		$this->data['Evaluateddrug']['brand_name']=$data[2];
		$this->data['Evaluateddrug']['preparation']=$data[3];
		$this->data['Evaluateddrug']['quantity']=$data[4];
		$this->data['Evaluateddrug']['unit_price']=str_replace(',', '', $data[5]);
		$this->data['Evaluateddrug']['actual_charge']=str_replace(',', '', $data[6]);
		$this->data['Evaluateddrug']['claim_hospital']=str_replace(',', '', $data[7]);
		$this->data['Evaluateddrug']['claim_patient']=str_replace(',', '', $data[8]);
		$this->data['Evaluateddrug']['status']=1;				
		
		$this->Evaluateddrug->create();
		$this->Evaluateddrug->save($this->data);
	}
	function setStatus($id, $status){
		$this->data['Evaluateddrug']['id']=$id;
		$this->data['Evaluateddrug']['status']=$status;
		
		$this->Evaluateddrug->save($this->data);
	}
	function getTotalClaimHospital($claimid){
		$this->view='Json';
		
		$field=array('SUM(claim_hospital) as claim_hospital');
		$condition=array('claimid'=>$claimid, 'status'=>1);
		$data=$this->Evaluateddrug->find('all', array('conditions'=>$condition, 'fields'=>$field));
		
		$this->set('data', $data);									
		$this->set('json', 'data');
	}
	function getDrug($claimid){
		$this->view='Json';
		
		$condition=array('claimid'=>$claimid);
		$data=$this->Evaluateddrug->find('all', array('conditions'=>$condition));
		
		$this->set('data', $data);									
		$this->set('json', 'data');
	}
	function update(){
		$id=$_POST['id'];
		$quantity=$_POST['quantity'];
		$unit_price=$_POST['unit_price'];
		$total=$quantity*$unit_price;
		
		$this->data['Evaluateddrug']['id']=$id;
		$this->data['Evaluateddrug']['quantity']=$quantity;
		$this->data['Evaluateddrug']['unit_price']=$unit_price;		
		$this->data['Evaluateddrug']['claim_hospital']=$total;
		
		$this->Evaluateddrug->save($this->data);
	}
}
?>